import { AppTemplateItem, DetailItem, DnTableItem, DnTableParam, EditDnParam } from './model/tenantAppModel';
import { deployHttp, tenantHttp } from '/@/utils/http/axios';
enum Api {
  GET_APP_TEMPLATE = '/app/appList',
  MANAGE_DN = '/v1/app/getZoneName',
  DETAIL = '/app/subAppDetail',
  EIDT = '/v1/app/editZoneName',
}

//获取上架应用信息
export const getAppTemplate = async () => {
  const res = await tenantHttp.get<AppTemplateItem[]>({
    url: Api.GET_APP_TEMPLATE,
  });
  res.map((item) => {
    item.isSubscribedStr = item.isSubscribed ? '已订阅' : '未订阅';
    return item;
  });
  return res;
};

//获取域名管理页面
export const getDnTable = async (params: DnTableParam) => {
  const res = await deployHttp.get<DnTableItem>({
    url: Api.MANAGE_DN,
    params,
  });
  return res;
};
//编辑域名
export const editDn = async (params: EditDnParam) => {
  const res = await deployHttp.post<string>({
    url: Api.EIDT,
    params,
  });
  return res;
};

//获取订阅详情
export const getSubscribeDetail = async (params: number) => {
  const res = await tenantHttp.get<DetailItem>({
    url: Api.DETAIL,
    params: { appId: params },
  });

  res.paymentTypeStr = 'postpaid' == res.paymentType ? '按需付费' : '包周期';
  return res;
};
